﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Shohdi.DataHandler;
using DatabaseComponent;


public partial class RegisterAccountAR : System.Web.UI.Page
{



   


    protected void Page_Load(object sender, EventArgs e)
    {


       




        if (!Page.IsPostBack)
        {

            bindDropDown();

            
        }
    }



    /// <summary>
    /// this will bind all drop downs
    /// </summary>
    private void bindDropDown()
    {
        bindBusinessLine();

        bindArea();

    }


    /// <summary>
    /// this function will bind area to drop down
    /// </summary>
    private void bindArea()
    {
        AreaDB objDB = new AreaDB(ConnectionStrings.LMS);
        List<Area> lstArea = objDB.Select("", "");

        lstArea = (from obj in lstArea where obj.ParentID == null orderby obj.AreaNameAR select obj).ToList<Area>();

        lstArea.Insert(0, new Area() { ID = -1, AreaNameAR = "-- اختر --" });

        ddlArea.DataSource = lstArea;
        ddlArea.DataTextField = "AreaNameAR";
        ddlArea.DataValueField = "ID";
        ddlArea.DataBind();
    }



    /// <summary>
    /// this function will bind the bussiness line drop down
    /// </summary>
    private void bindBusinessLine()
    {
        List<OrgnizationChart> obj = new List<OrgnizationChart>();
        OrgnizationChartDB objDB = new OrgnizationChartDB(ConnectionStrings.LMS);

        obj = objDB.Select("", "");

        obj = (from obj1 in obj where obj1.objParent.ParentID == null && obj1.ChartTypeID == 2 orderby obj1.NameAR  select obj1).ToList<OrgnizationChart>();

        obj.Insert(0, new OrgnizationChart() { ID = -1, NameAR = "-- اختر --" });

        ddlBusinessLine.DataSource = obj;
        ddlBusinessLine.DataTextField = "NameAR";
        ddlBusinessLine.DataValueField = "ID";
        ddlBusinessLine.DataBind();
    }












    protected void cvBusinessLine_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (ddlBusinessLine.Items.Count == 0)
            args.IsValid = false;
        else if (ddlBusinessLine.SelectedValue == "-1")
            args.IsValid = false;
        else
            args.IsValid = true;
            
    }
    protected void cvArea_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (ddlArea.Items.Count == 0)
            args.IsValid = false;
        else if (ddlArea.SelectedValue == "-1")
            args.IsValid = false;
        else
            args.IsValid = true;
    }
    protected void cvImage_ServerValidate(object source, ServerValidateEventArgs args)
    {
        args.IsValid = ricCheckImage.isOk;
        ricCheckImage.clear();

    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            SupportMainMailDB objDB = new SupportMainMailDB(ConnectionStrings.LMS);
            List<SupportMainMail> lst = objDB.Select("", "");
            if (lst.Count > 0)
                GlobalVars.SendRequestMail(@"طلب حساب جديد في نظام ""أنا أتعلم""", createMessageText(), lst[0].Email);


            //GlobalVars.SendRequestMail(@"طلب حساب جديد في نظام ""أنا أتعلم""", createMessageText(), "hrd-elearning@se.com.sa");


            lblResult.Text = "تم ارسال رسالتك بنجاح.";

            ScriptManager.RegisterStartupScript(this, this.GetType(), "scriptMessage", "alert('تم ارسال رسالتك بنجاح.');", true);

            clearAllControls();
        }
    }



    protected void btnClear_Click(object sender, EventArgs e)
    {
        clearAllControls();

    }



    /// <summary>
    /// this function will clear all controls
    /// </summary>
    private void clearAllControls()
    {
        txtFullName.Text = "";
        txtEnglishFullName.Text = "";
        txtBadge.Text = "";
        txtEmail.Text = "";
        ddlBusinessLine.SelectedValue = "-1";
        txtSector.Text = "";
        txtManagement.Text = "";
        txtChargeAccount.Text = "";
        ddlArea.SelectedValue = "-1";
        txtNat.Text = "";
        ricCheckImage.clear();
    }




    private string createMessageText()
    {
        string strMessage = @"

<div style=""width:500px; text-align:right; direction:rtl;"">

 <div style=""width:500px;"">
            
            <div style=""float:right; width:120px;text-aliagn:center; height:1px;font-size:1px;""></div>

            <div style=""float:right; width:35px;font-size:1px;height:1px;""></div>

            <div style=""float:right; width:300px; text-align:center;color:#333399;font-size:18px;"">

                طلب حساب جديد في نظام ""أنا أتعلم"" 
            
            </div>
       
            


            <div style=""clear:both;""></div>
       </div>
       
       <div style=""clear:both; height:10px;""></div>



       <div style=""width:500px;"">
            
            <div style=""float:right; width:120px;text-aliagn:center;"">الاسم الثلاثي العربي</div>

            <div style=""float:right; width:35px;font-size:1px;height:1px;""></div>

            <div style=""float:right; width:300px;"">
                           " + txtFullName.Text  + @"
            </div>
           
            <div style=""float:right;"">
                    
            </div>
           

            <div style=""clear:both;""></div>
       </div>
       
       <div style=""clear:both; height:10px;""></div>
       
       <div style=""width:500px;"">
            
            <div style=""float:right; width:120px;text-aliagn:center;"">الاسم الثلاثي الانجليزي</div>

            <div style=""float:right; width:35px;font-size:1px;height:1px;""></div>

            <div style=""float:right; width:300px;"">
                           " + txtEnglishFullName.Text + @"
            </div>
           
            <div style=""float:right;"">
                    
            </div>
           

            <div style=""clear:both;""></div>
       </div>
       
       <div style=""clear:both; height:10px;""></div>



       <div style=""width:500px;"">
            
            <div style=""float:right; width:120px;text-aliagn:center;"">الرقم الوظيفي</div>

            <div style=""float:right; width:35px;font-size:1px;height:1px;""></div>

            <div style=""float:right; width:300px;"">
                           " + txtBadge.Text  + @"
            </div>
           
            <div style=""float:right;"">
                    
            </div>
           

            <div style=""clear:both;""></div>
       </div>
       
       <div style=""clear:both; height:10px;""></div>

        <div style=""width:500px;"">
            
            <div style=""float:right; width:120px;text-aliagn:center;"">
                البريد الالكتروني
            </div>

            <div style=""float:right; width:35px;font-size:1px;height:1px;""></div>

            <div style=""float:right; width:300px;"">
                " + txtEmail.Text +  @"
            </div>
           
            <div style=""float:right;"">
                   
            </div>
           

            <div style=""clear:both;""></div>
       </div>
       
       <div style=""clear:both; height:10px;""></div>

       



       <div style=""width:500px;"">
            
            <div style=""float:right; width:120px;text-aliagn:center;"">النشاط</div>

            <div style=""float:right; width:35px;font-size:1px;height:1px;""></div>

            <div style=""float:right; width:300px;"">
                " + ddlBusinessLine.SelectedItem.Text + @"
            </div>
           
            <div style=""float:right;"">
                  
                
            </div>
           

            <div style=""clear:both;""></div>
       </div>
       
       <div style=""clear:both; height:10px;""></div>




       <div style=""width:500px;"">
            
            <div style=""float:right; width:120px;text-aliagn:center;"">القطاع</div>

            <div style=""float:right; width:35px;font-size:1px;height:1px;""></div>

            <div style=""float:right; width:300px;"">
                           "+ txtSector.Text +@"
            </div>
           
            <div style=""float:right;"">
                    
            </div>
           

            <div style=""clear:both;""></div>
       </div>
       
       <div style=""clear:both; height:10px;""></div>


       <div style=""width:500px;"">
            
            <div style=""float:right; width:120px;text-aliagn:center;"">الادارة</div>

            <div style=""float:right; width:35px;font-size:1px;height:1px;""></div>

            <div style=""float:right; width:300px;"">
                           " + txtManagement.Text  + @"
            </div>
           
            <div style=""float:right;"">
                    
            </div>
           

            <div style=""clear:both;""></div>
       </div>
       
       <div style=""clear:both; height:10px;""></div>


       <div style=""width:500px;"">
            
            <div style=""float:right; width:120px;text-aliagn:center;"">رمز مركز التكلفة</div>

            <div style=""float:right; width:35px;font-size:1px;height:1px;""></div>

            <div style=""float:right; width:300px;"">
                           " + txtChargeAccount.Text  + @"
            </div>
           
            <div style=""float:right;"">
                    
            </div>
           

            <div style=""clear:both;""></div>
       </div>
       
       <div style=""clear:both; height:10px;""></div>


       <div style=""width:500px;"">
            
            <div style=""float:right; width:120px;text-aliagn:center;"">المنطقة</div>

            <div style=""float:right; width:35px;font-size:1px;height:1px;""></div>

            <div style=""float:right; width:300px;"">
                "  + ddlArea.SelectedItem.Text + @"
            </div>
           
            <div style=""float:right;"">
                  
                  
            </div>
       
           

            <div style=""clear:both;""></div>
       </div>
       
       <div style=""clear:both; height:10px;""></div>




       <div style=""width:500px;"">
            
            <div style=""float:right; width:120px;text-aliagn:center;"">الجنسية</div>

            <div style=""float:right; width:35px;font-size:1px;height:1px;""></div>

            <div style=""float:right; width:300px;"">
                           "+ txtNat.Text +@"
            </div>
           
            <div style=""float:right;"">
                    
            </div>
           

            <div style=""clear:both;""></div>
       </div>
       
       <div style=""clear:both; height:10px;""></div>


<div style=""clear:both;""></div>
    </div>





";



        return strMessage;
    }
    
}
